-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Disable linker relaxed addressing when loading gp #137
Conversation
Sorry guys, I updated our nuttx baseline to be on top of released 12.1.0, so now these PR's need rebase... |
Need to rebase this after sbi code relocation is done, as this code is also relocated into different source file. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tried this, works after the relocation changes. I wonder what was the original reason to not have this way, maybe at mpfs_head.S (we have it there, is the other unnecessary in this patch?):
.option push
.option norelax
la gp, __global_pointer$
.option pop
got it wrong (in mpfs_head.S), or maybe a different toolchain was used, or something else I don't know.
1d09080
to
bea6b63
Compare
Every time the global pointer is loaded, linker relaxation needs to be disabled. This can break randomly, if __global_pointer$ is placed within gp-relative load addresses. The only way to ensure gp is not loaded via gp-relative (relaxed) loads, is to explicitly tell the linker not to use relaxation. Linux trap entry does exactly this, it (re-)loads gp when entering kernel. Semantically this is the same thing as going between opensbi <-> kernel. Same is done when initializing the kernel: |
Yes, looks like the gp is already set before the mpfs_opensbi_prepare_hart() is called, so in that sense the gp loading in _prepare_hart function could be removed. |
It all depends if opensbi uses gp relative instructions. I'm more concerned about mpfs_exception_opensbi. I think our bootloader uses gp-relative instructions but it sets gp in mpfs_head.S so in this case setting it (again) in mpfs_opensbi_prepare_hart() should be unnecessary. |
bea6b63
to
6b37e74
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
No description provided.